/*
 * Created on 29.08.2007
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package at.fhv.dcs.aw.j2me.lcdui.lowlevel.sort;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class DoubleBufferingSortingCanvas extends SortingCanvas {
    private Image m_buffer;
    private Graphics m_graphics;
    
    public DoubleBufferingSortingCanvas() {
        m_buffer = Image.createImage(getWidth(), getHeight());
        m_graphics = m_buffer.getGraphics();
        
    }
    protected void paint(Graphics g) {
        int mid = m_buffer.getWidth() / 2;
        
        //clear area
        m_graphics.setColor(WHITE);
        m_graphics.fillRect(0, 0, m_buffer.getWidth(), m_buffer.getHeight());
        
        m_graphics.setColor(BLACK);
        synchronized (m_values) {
            for (int i = 0; i < m_values.length; i++) {
                m_graphics.drawLine(mid - m_values[i], i , mid + m_values[i], i);
            }
        }
        
        g.drawImage(m_buffer, 0, 0, Graphics.TOP | Graphics.LEFT);
    }
}